<?php

namespace app\shopping\controller;

use think\Controller;

class Record extends Controller
{
    public function __construct(){
        parent::__construct();

        $this->model = model('Business.Record');
        $this->BusinessModel = model('Business.User');
    }

    /**
     * 消费记录列表
     *
     * @ApiTitle    (消费记录列表)
     * @ApiSummary  (消费记录列表)
     * @ApiMethod   (POST)
     * @ApiParams   (name="busid", type="int", required=true, description="客户ID")
     * @ApiParams   (name="page", type="int", required=true, description="页码")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
        'code':'1',
        'msg':'返回成功'
    * })
    */
    public function index(){
        if($this->request->isPost()){
            $busid = $this->request->param('busid',0,'trim');
            $page = $this->request->param('page',1,'trim');
            $limit = 10;

            // 偏移量
            $offset = ($page-1) * $limit;

            // 查询用户
            $business = $this->BusinessModel->find($busid);
            if(!$business){
                $this->error('用户未知');
                exit;
            }

            $list = $this->model
                ->where(['busid'=>$busid])
                ->order('id','desc')
                ->limit($offset,$limit)
                ->select();

            if($list){
                $this->success('成功返回消费记录',null,$list);
                exit;
            }else{
                $this->error('暂无更多记录返回');
                exit;
            }

        }
    }

}
